clear all
set more off

local out2="\outregsQJE\"
local SSA="\Data_and_Codes\"
cd "\workfiles"

use step001_QJE_2, clear

*** join SSA data
joinby firm_id time using "`SSA'CGR_2006q1_2019q1_clean_ONLYINPSADD.dta", unmatched(master)
tab _merge
drop _merge

joinby firm_id time using "`SSA'CGR_2006q1_2019q1_clean_ONLYINPSWAGE.dta", unmatched(master)
tab _merge
drop _merge

tsset firm_id time

*** define treatment as given inflation TIMES treatment status
gen Treat=treatment_old*infl

*** winsorize actual and expected price changes
winsor dpre, gen(dpre_w) p(0.02)
winsor dprez, gen(dprez_w) p(0.02)

local controls0=" l2.dprez_w  i.l2.sitimp5 i.l2.occtot i.l2.sitgen i.l2.promig i.l2.liquid "	

*** restrict the sample only to the period with treatment and control groups
keep if time>=208

***=============================================================================
*** 						Panel A: price response
***=============================================================================

forvalues i=0(1)5 {

	ivreghdfe f`i'.dpre_w `controls0' l.it12_all ///
			[aw=peso] if l.Treat~=., ffirst dkraay(2) absorb(i.setton5#i.trimestre) 
		
	if `i'==0 {	
		outreg2 using "`out2'Appendix_Table05_PanelA.dta", replace dta dec(3) 	
	}
	else {
		outreg2 using "`out2'Appendix_Table05_PanelA.dta", append dta dec(3) 
	}
}

***=============================================================================
*** 						Panel B: employment (SIGE) response
***=============================================================================

forvalues i=0(1)5 {

	gen FC`i'=f`i'.lnL-l.lnL
	winsor FC`i', gen(FC`i'_w2) p(0.02)

	ivreghdfe FC`i'_w2 `controls0' l.it12_all  ///
			[aw=peso] if l.Treat~=., ffirst dkraay(2) absorb(i.setton5#i.trimestre) 
		
	if `i'==0 {	
		outreg2 using "`out2'Appendix_Table05_PanelB.dta", replace dta dec(3) 	
	}
	else {
		outreg2 using "`out2'Appendix_Table05_PanelB.dta", append dta dec(3) 	
	}
}

***=============================================================================
*** 						Panel C: employment (SSA) response
***=============================================================================

gen lnL_new=log(add_new)*100

forvalues i=0(1)5 {
	capture drop FC`i'
	gen FC`i'=f`i'.lnL_new-l.lnL_new
	capture drop FC`i'_w2 
	winsor FC`i', gen(FC`i'_w2) p(0.02)

	ivreghdfe FC`i'_w2 `controls0' l.it12_all ///
			[aw=peso] if l.Treat~=., ffirst dkraay(2) absorb(i.setton5#i.trimestre) 
		
	if `i'==0 {	
		outreg2 using "`out2'Appendix_Table05_PanelC.dta", replace dta dec(3)
	}
	else {
		outreg2 using "`out2'Appendix_Table05_PanelC.dta", append dta dec(3)	
	}
}


***=============================================================================
*** 						Panel D: wages (SSA) response
***=============================================================================

gen lnwage=log(wagebill/add_new)*100
winsor lnwage, gen(lnwage_w) p(0.02)
replace lnwage=lnwage_w

forvalues i=0(1)5 {
	capture drop FC`i'
	gen FC`i'=f`i'.lnwage_w-l.lnwage_w
	capture drop FC`i'_w2 
	winsor FC`i', gen(FC`i'_w2) p(0.02)

	ivreghdfe FC`i'_w2 `controls0' l.it12_all  ///
			[aw=peso] if l.Treat~=., ffirst dkraay(2) absorb(i.setton5#i.trimestre) 
		
	if `i'==0 {	
		outreg2 using "`out2'Appendix_Table05_PanelD.dta", replace dta dec(3)
	}
	else {
		outreg2 using "`out2'Appendix_Table05_PanelD.dta", append dta dec(3) 
	}
}


